<template>
  <div>
    <el-card class="box-card" style="margin: 20px">
      <div slot="header" class="clearfix">
        <div class="tipText">
          <p>智育素质评分标准</p>
          <p>
            智育素质主要考察学生在学习能力、创新能力等方面的综合表现，以学生的学业成绩和创新能力成绩为测评依据。具体计算方法为：
          </p>
          <p>
            1.智育素质测评成绩(C2，60分）=学业成绩(Z1，55分)+资格证书成绩(Z2，5分)
          </p>
          <p>
            2.各类资格证书加分，最高分不超过5分。（多本同类的证书不重复加分，按最高级别加分；获得其余等级证书酌情加分）
          </p>
          <table border class="table">
            <tr>
              <th style="width: 30px">序号</th>
              <th>要素</th>
              <th>分值</th>
            </tr>
            <tr>
              <th>1</th>
              <td>英语等级证书（达到要求的加0.5分，每高一级再加0.5分）</td>
              <td rowspan="4">1-4类证书每学期可重复加分。</td>
            </tr>
            <tr>
              <th>2</th>
              <td>普通话证书（普通话二乙加0.5分，每高一级再加0.5分）</td>
            </tr>
            <tr>
              <th>3</th>
              <td>计算机证书（达到要求的加0.5分，每高一级再加0.5分）</td>
            </tr>
            <tr>
              <th>4</th>
              <td>
                教师资格证书笔试2门、面试都过加1分，其中过一门笔试加0.2分。
              </td>
            </tr>
            <tr>
              <th>5</th>
              <td>
                大学阶段获全国书法、全国美术类六级、浙江省音乐测试八级及以上级别加0.5分，每高一级再加.0.3分。
              </td>
              <td rowspan="5">5-9类证书仅证书获得学期加分。</td>
            </tr>
            <tr>
              <th>6</th>
              <td>大学阶段获国家三级裁判加0.2分，每高一级再加.0.3分。</td>
            </tr>
            <tr>
              <th>7</th>
              <td>
                大学阶段获幼儿舞蹈教师资格证（1-3级）、钢琴教师资格证、母婴护理证、体育舞蹈教师资格证（拉丁舞二级、国标舞）的加0.5分。
              </td>
            </tr>
            <tr>
              <th>8</th>
              <td>
                大学阶段参加本科学历继续学习的（报名专升本函授）交报名费后加0.5分，以后每合格一门再加0.1分；参加自考学习的，每考出一门加0.1分。
              </td>
            </tr>
            <tr>
              <th>9</th>
              <td>大学阶段获专业的X证书，加1分。</td>
            </tr>
          </table>
        </div>
      </div>

      <div>
        <avue-form
          v-if="update"
          ref="form"
          v-model="obj"
          :option="option"
          @reset-change="emptytChange"
          :rules="rules"
          :defaults.sync="defaults"
          class="typeClass2"
        >
          <template slot="menuForm">
            <el-button
              icon="el-icon-edit"
              type="primary"
              @click="submit"
              v-if="butDis"
              >提 交</el-button
            >
            <el-button
              icon="el-icon-edit"
              @click="updateSub"
              type="primary"
              v-else
              >更新</el-button
            >
          </template>
        </avue-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import { baseUrl } from "@/config/env";
import { httpCheck } from "@/api/studentsPage/approval";
import { willHttp } from "@/api/teacherPage/review";

export default {
  data() {
    return {
      update: true,
      // 控制更新、新增按钮
      butDis: true,
      obj: {
        type: "",
      },
      // 控制类型选择框
      disSelect: true,
      defaults: {},
      option: {
        size: "mini",
        mockBtn: false,
        submitBtn: false,
        printBtn: false,
        column: [
          {
            label: "证书类型",
            span: 10,
            prop: "type",
            type: "cascader",
            dicData: [
              {
                label: "英语等级证书",
                value: 10,
                children: [
                  {
                    label: "英语A级",
                    value: 10,
                  },
                  {
                    label: "英语B级",
                    value: 20,
                  },
                  {
                    label: "英语三级",
                    value: 30,
                  },
                  {
                    label: "英语四级",
                    value: 40,
                  },
                  {
                    label: "英语六级",
                    value: 50,
                  },
                ],
              },
              {
                label: "普通话证书证书",
                value: 20,
                children: [
                  {
                    label: "普通话二乙",
                    value: 10,
                  },
                  {
                    label: "普通话二甲",
                    value: 20,
                  },
                  {
                    label: "普通话一乙",
                    value: 30,
                  },
                  {
                    label: "普通话一甲",
                    value: 40,
                  },
                ],
              },
              {
                label: "计算机证书",
                value: 30,
                children: [
                  {
                    label: "计算机一级",
                    value: 10,
                  },
                  {
                    label: "计算机二级",
                    value: 20,
                  },
                  {
                    label: "计算机三级",
                    value: 30,
                  },
                  {
                    label: "计算机四级",
                    value: 40,
                  },
                ],
              },
              {
                label: "教师资格证书",
                value: 40,
                children: [
                  {
                    label: "一门笔试",
                    value: 10,
                  },
                  {
                    label: "两门笔试",
                    value: 20,
                  },
                  {
                    label: "笔试面试全过",
                    value: 30,
                  },
                ],
              },
              {
                label: "书法美术类证书",
                value: 50,
              },
              {
                label: "国家级证书书",
                value: 60,
              },
              {
                label: "婴幼儿、钢琴教师、体育舞蹈教师...资格证证书",
                value: 70,
              },
              {
                label: "本科学历证书",
                value: 80,
              },
            ],
            rules: [
              {
                required: true,
                message: "请输入证书类型",
                trigger: "blur",
              },
            ],
          },
          {
            label: "证书名称",
            prop: "title",
            type: "input",
            span: 10,
            rules: [
              {
                required: true,
                message: "请输入证书名称",
                trigger: "blur",
              },
            ],
          },
          {
            label: "证书获得时间",
            prop: "getTime",
            type: "datetime",
            labelWidth: 110,
            span: 10,
            format: "yyyy-MM-dd",
            valueFormat: "timestamp",
            mock: {
              type: "datetime",
              now: true,
            },
            rules: [
              {
                required: true,
                message: "请输入时间",
                trigger: "blur",
              },
            ],
          },
          {
            label: "申报分数",
            prop: "applyFraction",
            display: false,
            type: "number",
            precision: 1,
            controlsPosition: "",
            span: 10,
          },
          {
            label: "申报理由",
            span: 18,
            prop: "adit",
            type: "textarea",
            mock: { type: "textarea" },
          },
          {
            label: "附件上传",
            prop: "imgUrl",
            type: "upload",
            propsHttp: {
              home: baseUrl,
              res: "data",
            },
            props: {
              value: "url",
              label: "name",
            },
            span: 24,
            listType: "picture-card",
            tip: "只能上传jpg/png文件，且不超过500kb",
            action: baseUrl + "/basic/sys-file-log/upload",
          },
        ],
      },
    };
  },
  computed: {
    // option() {
    //   return {};
    // }
  },
  watch: {
    disSelect(val) {
      let type = document.getElementsByClassName("typeClass")[0];
      if (val) {
        type.style.visibility = "visible";
      } else {
        type.style.visibility = "hidden";
        this.obj.type = "";
      }
    },
    "obj.type"(val) {
      if (val[0] == 10 || val[0] == 20 || val[0] == 30 || val[0] == 40) {
        this.option.column[3].display = false;
        console.log("111");
      } else {
        this.option.column[3].display = true;
      }
    },
  },
  async mounted() {
    let id = this.$route.query.id;
    if (id) {
      await willHttp("certificate", id).then((res) => {
        this.obj.adit = res[0].data.remark;
        this.obj.applyFraction = res[0].data.applyFraction;
        if (res[0].data.type) {
          if (
            res[0].data.type[0] == 10 ||
            res[0].data.type[0] == 20 ||
            res[0].data.type[0] == 30 ||
            res[0].data.type[0] == 40
          ) {
            this.obj.type = res[0].data.type;
            this.obj.level = res[0].data.level;
          } else {
            this.obj.type = "";
          }
        }
        this.obj.getTime = res[0].data.getTime;
        this.obj.isForever = res[0].data.isForever;
        this.obj.title = res[0].data.title;
        this.obj.imgUrl = res[0].data.files;
        this.butDis = false;
      });
    }
  },

  methods: {
    // 更新
    updateSub() {
      this.submitParams("update");
    },
    // 提交done
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitParams();
        } else {
          return false;
        }
      });
    },
    async submitParams(par) {
      let params = {};
      params.files = this.obj.imgUrl;
      params.remark = this.obj.adit;
      params.applyFraction = this.obj.applyFraction;
      params.getTime = this.obj.getTime;
      if (
        this.obj.type[0] == 10 ||
        this.obj.type[0] == 20 ||
        this.obj.type[0] == 30 ||
        this.obj.type[0] == 40
      ) {
        this.obj.isForever = true;
        params.type = this.obj.type[0];
        params.level = this.obj.type[1];
      } else {
        this.obj.isForever = false;
        params.type = "";
      }
      params.isForever = this.obj.isForever;
      params.title = this.obj.title;
      console.log(params);
      if (par) {
        params.id = this.$route.query.id;

        httpCheck("certificate", params, "PUT").then((res) => {
          if (res.code == 1) {
            this.submitFun(par);
          } else {
            this.reload();
            this.$message.error(res.message);
          }
        });
      } else {
        httpCheck("certificate", params, "POST").then((res) => {
          if (res.code == 1) {
            this.submitFun();
            this.obj.type;
          } else {
            this.reload();
            this.$message.error(res.message);
          }
        });
      }
    },
    submitFun(par) {
      if (par) {
        var arr = [" 更新成功", " 将在3s后自动跳转到申报详情页面"];
      } else {
        arr = [" 提交成功", " 将在3s后自动跳转到申报详情页面"];
      }
      let str = arr.join(" <br/> <br/> ");
      this.$message({
        dangerouslyUseHTMLString: true,
        message: str,
        type: "success",
      });
      setTimeout(() => {
        this.$router.push("/studentsPage");
        this.reload();
        this.emptyChange();
      }, 3000);
    },

    reload() {
      this.update = false;
      this.$nextTick(() => {
        this.update = true;
      });
    },
    // 清空方法
    emptyChange() {
      this.obj = {};
    },
  },
};
</script>
<style>
.tipText p {
  text-indent: 2em;
}
.tipText {
  border: 1px solid #455;
  height: 200px;
  overflow: auto;
  padding: 25px;
  padding-top: 0;
  font-size: 13px;
  font-weight: 300;
}
.typeClass {
  left: 0px;
  display: true;
  top: -5.5px;
  position: absolute;
  z-index: 3000;
}
.typeClass2 {
  margin-top: -13px;
}
.table {
  border-collapse: inherit;
}
</style>
